import { createStore } from "vuex";
import { ref } from "vue"
import user from "../../Api/user.js";



const store = createStore({
  state: () => ({
    //地址下标
    addindex: 0,
    token: '',
    //验证码
    Verificationcode: 0,
    //地址列表
    // addressList: [{
    //   title: "北京市市辖区东城区璃月",
    //   text: "巴尔泽布",
    //   phone: "133323356562"
    // }]
  }),
  mutations: {
    // 添加地址
    // append(state, payload) {
    //   state.addressList.push(payload)
    // },
    //点击地址获取地址列表的下表
    // changeaddindex(state, payload) {
    //   state.addindex = payload
    // },
    // 更改验证码的值
    Verificationcode(state, payload) {
      state.Verificationcode = payload
    },
    //更改token的值
    token(state, payload) {
      state.login.token = payload
    }
  },
  // getters: {
  // 获取地址列表中的一个
  //   addindexlist(state) {
  //     return state.addressList[state.addindex]
  //   }
  // },
  actions: {
    // 验证码
    loginVerificationcode(state, payload) {
      console.log(1);
      // return user.login({ mobile: payload }).then((res) => {
      //   state.commit("Verificationcode", res.data.data.code)
      // });
    },
    // 登录
    loginverify(state, payload) {
      console.log(payload);
      return user.loginverify({
        mobile: payload.phone,
        code: payload.password
      }).then((res) => {
        state.commit("token", res.data.data.token.token)
        // console.log();
      })
    },
  }
  

});

export default store;
